package com.grupoconstruobras.sigo.core.config;

import com.grupoconstruobras.sigo.datatransfer.ResultSet;
import com.grupoconstruobras.sigo.ServiceException;
import com.grupoconstruobras.sigo.general.ICrudManager;
import com.grupoconstruobras.sigo.general.util.GenericJPAManager;

import java.lang.reflect.InvocationTargetException;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.apache.commons.beanutils.BeanUtils;

@Stateless(name = "parametroConfigAppManager", mappedName = "manager/parametroConfigAppManager")
@EJB(beanName = "parametroConfigAppManager", beanInterface = ICrudManager.class, name = "ejb/service/parametroConfigAppManager")
public class ParamConfigAppMgrEjb extends
		GenericJPAManager<ParametroConfigApp, Long> implements
		ICrudManager<Long, ParametroConfigApp> {

	@Override
	public ParametroConfigApp save(ParametroConfigApp entity)
			throws ServiceException {
		entity = super.create(entity);
		return entity;
	}

	@Override
	public ParametroConfigApp merge(Long id, ParametroConfigApp entity)
			throws ServiceException {
		ParametroConfigApp persist = selectById(id);
		try {
			entity.setId(id);
			BeanUtils.copyProperties(persist, entity);
		} catch (IllegalAccessException | InvocationTargetException e) {
			throw new ServiceException(e.getMessage(), e);
		}
		entity = super.update(persist);
		return entity;
	}

	@Override
	public void remove(Long id) throws ServiceException {
		super.deleteById(id);
	}

	@Override
	public ParametroConfigApp getById(Long id) throws ServiceException {
		ParametroConfigApp entity = super.selectById(id);
		return entity;
	}

	@Override
	public ResultSet<ParametroConfigApp> filter(ParametroConfigApp entity,
			Integer offset, Integer limit) throws ServiceException {
		return new ResultSet<ParametroConfigApp>(null, super.findAll());
	}

}
